﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DrugsShopManagement.DBCLASS;

namespace DrugsShopManagement
{
    public partial class FormWarn : Form
    {
        public FormWarn()
        {
            InitializeComponent();
        }
        Operator op = new Operator();
        public void jgtx()//库存不足药品提醒
        {
            DataTable dt_a = new DataTable();
            string sq_ccid = "Select * from drugsStore";//库存表中药品ID
            dt_a = op.getDataTable(sq_ccid, "drugsStore ");
            int n;//库存表行数

            DataTable dt_b = new DataTable();
            string sq_wid = "Select * from drugsWarning";//报警值表中药品ID
            dt_b = op.getDataTable(sq_wid, "drugsWarning ");
            int m;//报警值表行数

            for (n = 0; n < dt_a.Rows.Count; n++)
            {
                for (m = 0; m < dt_b.Rows.Count; m++)
                {
                    int Strccid = Convert.ToInt32(dt_a.Rows[n][1]);//库存表每行药品ID
                    int strccno = Convert.ToInt32(dt_a.Rows[n][16]);//库存表每行药品库存量
                    int strwid = Convert.ToInt32(dt_b.Rows[m][0]);//报警值表每行药品ID
                    int strvno = Convert.ToInt32(dt_b.Rows[m][6]);//报警值表每行药品库存下限值

                    if (Strccid == strwid)
                    {
                        if (strccno < strvno)
                        {
                            textBox1.Text = textBox1.Text + dt_a.Rows[n][2] + ",库存量：" + dt_a.Rows[n][16]+ dt_a.Rows[n][5]+" / ";
                        }
                    }
                } 
            } 
        }

        public void jgtx1()//过期药品提醒
        {
            DataTable dt_a1 = new DataTable();
            string sq_ccid = "Select * from drugsStore";//库存表药品ID
            dt_a1 = op.getDataTable(sq_ccid, "drugsStore ");
            int n;//库存表行数
            DateTime nowtime=Convert.ToDateTime(DateTime.Now.ToString()) ;//获取当前时间
            
            for (n = 0; n < dt_a1.Rows.Count; n++)
            {
                DateTime Strcc =(DateTime)dt_a1.Rows[n][9];//库存表中药品有效期

                if (Strcc < nowtime)
                {
                    textBox2.Text = textBox2.Text + dt_a1.Rows[n][2] + ",有效期至：" + dt_a1.Rows[n][9] + " / ";
                }
            }
        }

        private void FormWarn_Load(object sender, EventArgs e)
        {
            jgtx();//库存不足药品提醒
            jgtx1();//过期药品提醒
        }
    }
}
